package ml.preprocessing.filter;

import weka.core.Capabilities;
import weka.core.Capabilities.Capability;
import weka.core.Instance;
import weka.core.Instances;
import weka.filters.SimpleStreamFilter;

public class MusicMergeFilter extends SimpleStreamFilter {

	private static final long serialVersionUID = 1L;
	private final double[] mean;

	public MusicMergeFilter(double[] mean) {
		super();
		this.mean = mean;
	}

	public String globalInfo() {
		return "music merge filter";
	}

	public Capabilities getCapabilities() {
		Capabilities result = super.getCapabilities();
		result.enableAllAttributes();
		result.enableAllClasses();
		result.enable(Capability.NO_CLASS);
		return result;
	}

	protected Instances determineOutputFormat(Instances inputFormat) {
		Instances result = new Instances(inputFormat, 0);
		return result;
	}

	protected Instance process(Instance inst) {
		double[] values = new double[inst.numAttributes()];
		for (int i = 0; i < mean.length; i++) {
			values[i] = Math.exp(Math.abs(mean[i] - inst.value(i)) * 2);
		}
		for (int i = mean.length; i < inst.numAttributes(); i++) {
			values[i] = inst.value(i);
		}
		Instance result = new Instance(1, values);
		return result;
	}
}
